let http=require('http');
let querystring=require('querystring');
module.exports=function (path,args){
	return new Promise(function (resolve,reject){
		const postData = querystring.stringify(args);

		const options = {
		  hostname: 'localhost',
		  port: 8008,
		  path: path,
		  method: 'POST',
		  headers: {
		    'Content-Type': 'application/x-www-form-urlencoded',
		    'Content-Length': Buffer.byteLength(postData)
		  }
		};

		const req = http.request(options, (res) => {
		  console.log(`状态码: ${res.statusCode}`);
		  console.log(`响应头: ${JSON.stringify(res.headers)}`);
		  res.setEncoding('utf8');
		  let rdata="";
		  res.on('data', (chunk) => {
		   rdata+=chunk;
		  });
		  res.on('end', () => {
		    resolve(JSON.parse(rdata));
		  });
		});

		req.on('error', (e) => {
		  console.error(`请求遇到问题: ${e.message}`);
		});

		// 写入数据到请求主体
		req.write(postData);
		req.end();

	});
}